﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sqlUser = "server=.;database=yangyong123;Integrate Security = True";
            SqlConnection sql = new SqlConnection(sqlUser);
            sql.Open();
            string myinsert = "insert into Student values ('" + textBox1.Text + "','" + textBox2.Text + "')";
            SqlCommand sqlCommand = new SqlCommand(myinsert,sql);          
            SqlDataReader dataReader = sqlCommand.ExecuteReader( );

            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("", sql);
            if (dataReader.HasRows)
            {
                MessageBox.Show("用户以注册，请重新注册");
            }
            else
            {
                sql.Close();
                MessageBox.Show("注册成功");

            }

        }
    }
}
